<template>
<page title="短信记录详情" has-back>
  <el-row justify="center">
    <el-col :span="15">
      <h1>详细信息</h1>
      <el-form :model="form" label-width="100px" label-position="right">
        <el-form-item label="收信人">
          {{form.receiver}}
        </el-form-item>
        <el-form-item label="发送时间">
          {{form.time}}
        </el-form-item>
        <el-form-item label="短信类型">
          {{form.type.name}}
        </el-form-item>
        <el-form-item label="短信内容">
          {{form.content}}
        </el-form-item>
        <el-form-item label="短信状态">
          <span :style="{ color:statusMap[form.status].color }">{{statusMap[form.status].msg}}</span>
        </el-form-item>
        <template v-if="form.status == 3">
          <el-form-item label="失败原因">
            {{form.error}}
          </el-form-item>
        </template>
      </el-form>
    </el-col>
  </el-row>
  <el-row justify="center">
    <el-button @click="$router.back()">返回</el-button>
    <el-button type="primary" @click="$router.back()">确认</el-button>
  </el-row>
</page>
</template>

<script>
import Page from "@/components/Page";
import axios from "axios";
import moment from "moment";
export default {
  name: "MessageInfo",
  components: {Page},
  data(){
    return{
      form:{
        time:'2021-03-11 09:23',
        type:'申请待审批信息',
        receiver:'张三',
        content:'尊敬的社会培训学院部门审批人陈翔龙：您有一条来自宁波生活垃圾分类指导中心的最新项目申请信息待批阅，请及时查看！',
        status:'3',
        error:'运营商错误',
      },
      statusMap:{
        1:{
          color:'rgb(103, 194, 58)',
          msg:'已发送'
        },
        2:{
          color:'rgb(230, 162, 60)',
          msg:'发送中'
        },
        3:{
          color:'rgb(245, 108, 108)',
          msg:'发送失败'
        }
      },
    }
  },
  methods:{
    findMessageRecord(id){
      return axios.get(this.$host+"/message/record/"+id).then((response)=>{
        if(response.data.code === 0){
          this.form = response.data.data;
          this.form.time = moment(this.form.time).format("YYYY-MM-DD hh-mm")
        }else{
          this.$message.error(response.data.msg);
        }
      })
    },
  },
  created() {
    this.findMessageRecord(this.$router.currentRoute.value.query.id);
  }
}
</script>

<style scoped>

</style>